var ValidateManager = function () {
	return {
		init:function() {
			jQuery.validator.addMethod("regex",  
				function(value, element, params) {  
					var exp = new RegExp(params);  
					return exp.test(value);  
				}, "格式错误");
			validator =$('.manager-form').validate({
				errorElement: 'span', //default input error message container
				errorClass: 'help-block', // default input error message class
				focusInvalid: false, // do not focus the last invalid input
				rules: {
					loginName: {
						required: true,
						regex:"^\\w+$",
						remote:{  
							type: "post",  
							url: ajaxUrl,  
							data: {  
								loginName: function() {  
									return $("#loginName").val();  
								},
								ajax:"checkUser"
							},  
							dataType: "json"
						}  
					},
					loginPwd: {
						required: true,
						rangelength:[5,16] 
					},
					reLoginPwd: {
						required: true,
						rangelength:[5,16] ,
						equalTo:"#loginPwd"
					},
					
				},

				messages: {
					loginName: {
						required: "用户名不能为空。",
						regex:"用户名只能用数字字母下划线。",
						remote:"用户名已占用！"
					},
					loginPwd: {
						required: "密码不能为空。",
						rangelength: "密码最少5个字符最多16个字符。"
					},
					reLoginPwd: {
						required: "密码不能为空。",
						rangelength: "密码最少5个字符最多16个字符。",
						equalTo:"请输入相同的密码！"
					}	
				},

				invalidHandler: function (event, validator) { //display error alert on form submit
					$('.alert-danger', $('.manager-form')).show();
				},

				highlight: function (element) { // hightlight error inputs
					$(element)
						.closest('.form-group').addClass('has-error'); // set error class to the control group
				},

				success: function (label) {
					label.closest('.form-group').removeClass('has-error');
					label.remove();
				},

				errorPlacement: function (error, element) {
					error.insertAfter(element.closest('.input-icon'));
				},

				submitHandler: function (form) {
					form.submit();
					
				}
			});
			
			
			

			$('.manager-form input').keypress(function (e) {
				if (e.which == 13) {
					if ($('.manager-form').validate().form()) {
						$('.manager-form').submit();
					}
					return false;
				}
			});
		}
    };
}();